#include <iostream>
#include <vector>
#include <string>
#include <sw/redis++/redis++.h>
#include "until.hpp"
#include <thread>
using namespace std;
using namespace chrono_literals;

void test1(sw::redis::Redis& redis)
{
    cout << "test zadd zrange" << endl;
    redis.flushall();

    redis.zadd("key1","吕布",99);
    
    redis.zadd("key1",
    {
        make_pair("赵云",98),
        make_pair("典韦",97),
    });

    vector<pair<string,double>> vpsd{
        make_pair("张飞",96),
        make_pair("关羽",95),
    };
    
    redis.zadd("key1",vpsd.begin(),vpsd.end());

    //俩种情况：
    //1.打印member 不带score
    //2.打印member 带score
    //给vector<string> 就只打印member      给vector<pair<string,double>>就打印 member score
    vector<string> vs;
    back_insert_iterator<vector<string>> it(vs);
    redis.zrange("key1",0,-1,it);
    PrintElenums(vs);

    vector<pair<string,double>> ret;
    back_insert_iterator<vector<pair<string,double>>> bit(ret);
    redis.zrange("key1",0,-1,bit);
    PrintElenums(ret);
}

void test2(sw::redis::Redis& redis)
{
    cout << "test zrem zrank zscore" << endl;
    redis.flushall();

    redis.zadd("key1","吕布",99);
    redis.zadd("key1","赵云",98);
    redis.zadd("key1","典韦",97);

    redis.zrem("key1","赵云");

    vector<pair<string,double>> ret;
    back_insert_iterator<vector<pair<string,double>>> bit(ret);
    redis.zrange("key1",0,-1,bit);
    PrintElenums(ret);

    sw::redis::OptionalLongLong oll = redis.zrank("key1","吕布");
    if(oll)
        cout << oll.value() << endl;
    else
        cout << "无效元素" << endl;
    sw::redis::OptionalDouble od = redis.zscore("key1","吕布");
    if(od)
        cout << od.value() << endl;
    else
        cout << "无效元素" << endl;
    
}

int main()
{
    sw::redis::Redis redistmp("tcp://127.0.0.1:6379");
    // test1(redistmp);
    test2(redistmp);
    return 0;
}